//
//  LoginViewController.m
//  嘀嘀拍
//
//  Created by wangjia_01 on 16/3/2.
//  Copyright © 2016年 wangjia_01. All rights reserved.
//

#import "LoginViewController.h"
#import "AppDelegate.h"

@interface LoginViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userNameTF;
@property (weak, nonatomic) IBOutlet UITextField *passwordTF;



@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    
   
    
    NSString *value=user_Object(@"username");
    
    if (value) {
        
        _userNameTF.text=user_Object(@"username");
        
        _passwordTF.text=user_Object(@"password");
    }
 
    
   // _bgImageHC.constant=__MainScreen_Height-20;
    
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)goBack:(id)sender {
    
    
    
}
- (IBAction)weiboLogin:(id)sender {
    
    
    
}
- (IBAction)goToLogin:(id)sender {
    
    
    if (!_userNameTF.text.length>0) {
        
        [SVProgressHUD showErrorWithStatus:@"用户名不能为空"];
        return;
    }
    if (!_passwordTF.text.length>0 && _passwordTF.text.length<6) {
        
        [SVProgressHUD showErrorWithStatus:@"密码不能少于6位"];
        return;
    }
    
    
    [httpRequest loginToHomePageBy:_userNameTF.text :_passwordTF.text :^(NSDictionary *dic) {
       
        DLog(@"%@",dic);
        
        if ([dic[@"code"] integerValue]==200) {
            
            User_Defaults(_userNameTF.text, @"username");
            User_Defaults(_passwordTF.text, @"password");
            User_Defaults(dic[@"data"][@"session_id"], @"session_id");
            User_Defaults_syn;
            
            
            //将session——id保存到属性表中
            AppDelegate *app=[[UIApplication sharedApplication] delegate];
            [app setTabbarHomePage];

        }else
        {
            [SVProgressHUD showErrorWithStatus:dic[@"message"]];
            
        
        }
        
    }];
    
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
